<?
include_once("_common.php");
@include_once("$g4[path]/lib/mw.builder.lib.php");
include_once("$mw_cash[path]/cybercash.lib.php");

$g4[title] = "$mw_cash[cf_cash_name] 이용내역";
include_once("_head.php");

$mb_id = $member['mb_id'];

if ($is_admin)
    $mb_id = 'ranger0401';

if (!is_numeric($page)) $page = 1;

$sql_common = " from $mw_cash[cash_list_table] ";
$sql_search = " where mb_id = '$mb_id' and cl_status = '1' ";
$sql_order = " order by cl_datetime desc ";

$sql = "select count(*) as cnt
        $sql_common
        $sql_search";
$row = sql_fetch($sql);
$total_count = $row[cnt];

$rows = $config[cf_page_rows];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함  */

$sql = "select *
        $sql_common
        $sql_search
        $sql_order
        limit $from_record, $rows ";
$qry = sql_query($sql);


$list = array();
for ($i=0; $row=sql_fetch_array($qry); $i++) {
    $list[$i] = $row;
    $list[$i][num] = $total_count - ($page - 1) * $rows - $i;
    $list[$i][cl_datetime] = date("Y-m-d", strtotime($list[$i][cl_datetime]));
    $href = "";

    $tmp = sql_fetch("select * from {$g4['write_prefix']}{$list[$i]['rel_table']} where wr_id = '{$list[$i]['rel_id']}'", false);
    if ($tmp) {
        $href = $g4['bbs_path']."/board.php?bo_table={$list[$i]['rel_table']}&wr_id={$list[$i]['rel_id']}";
        $list[$i]['cl_content'] = "<a href='{$href}' target='_blank' style='text-decoration:underline'>{$list[$i]['cl_content']}</a>";
    }
}

$list_count = count($list);

$write_pages = get_paging($rows, $page, $total_page, "$PHP_SELF?{$qstr}&page=");

$colspan = 4;

?>
<script src="http://pgweb.uplus.co.kr/WEB_SERVER/js/receipt_link.js"></script>
￼￼
<link rel="stylesheet" href="style.css" type="text/css"/>

<h3 class=title>● <?=$g4[title]?></h3>


<div style="height:20px; margin:10px 0 5px 0;">
    <div style="float:left; color:#888;"> 나의 <?=$mw_cash[cf_cash_name]?> :  <?=number_format($mw_cash[mb_cash])?> <?=$mw_cash[cf_cash_unit]?> </div>
    <div style="float:right; color:#888;"> 전체 <?=number_format($list_count)?> 건 </div>
</div>
<table border=0 cellpadding=0 cellspacing=0 width=100% class=data>
<colgroup width="50"/>
<colgroup width="100"/>
<colgroup width="100"/>
<colgroup width=""/>
<tr>
    <td class="head"> 번호 </td>
    <td class="head"> 날짜 </td>
    <td class="head"> <?=$mw_cash[cf_cash_name]?> </td>
    <td class="head"> 내용 </td>
</tr>

<? for ($i=0; $i<$list_count; $i++) { ?>
<?
$receipt = null;
if ($mw_cash[cf_lg_mid] && $mw_cash[cf_lg_mertkey]) {
    preg_match("/\[transaction\] => ([^\n]+)\n/", $list[$i][cl_paylog], $match);
    $tid = trim($match[1]);
    if (!$tid) {
        preg_match("/\[LGD_TID\] => ([^\n]+)\n/i", $list[$i][cl_paylog], $match);
        $tid = trim($match[1]);
    }

    preg_match("/\[oid\] => ([^\n]+)\n/i", $list[$i][cl_paylog], $match);
    $oid = trim($match[1]);
    if (!$oid) {
        preg_match("/\[LGD_OID\] => ([^\n]+)\n/i", $list[$i][cl_paylog], $match);
        $oid = trim($match[1]);
    }

    preg_match("/\[seqno\] => ([^\n]+)\n/i", $list[$i][cl_paylog], $match);
    $seq = trim($match[1]);
    if (!$seq) {
        preg_match("/\[LGD_SEQNO\] => ([^\n]+)\n/i", $list[$i][cl_paylog], $match);
        $seq = trim($match[1]);
    }

    $md5 = md5($mw_cash[cf_lg_mid].$tid.$mw_cash[cf_lg_mertkey]);

    preg_match("/\[receiptnumber\] => ([^\n]+)\n/i", $list[$i][cl_paylog], $match);
    $receipt_number = trim($match[1]);
    if (!$receipt_number) {
        preg_match("/\[LGD_CASHRECEIPTNUM\] => ([^\n]+)\n/i", $list[$i][cl_paylog], $match);
        $receipt_number = trim($match[1]);
    }

    if ($receipt_number) {
        $receipt = "showCashReceipts('{$mw_cash[cf_lg_mid]}', '{$oid}', '{$seq}', 'BANK', 'service')";
    }
    else if ($list[$i][cl_paytype] == '신용카드' or $list[$i][cl_paytype] == '계좌이체') {
        $receipt = "showReceiptByTID('{$mw_cash[cf_lg_mid]}', '{$tid}', '{$md5}')";
    }
}

?>
<tr>
    <td class="body"> <?=$list[$i][num]?> </td>
    <td class="body"> <?=$list[$i][cl_datetime]?> </td>
    <td class="body right">
        <?=number_format($list[$i][cl_cash])?> <?=$mw_cash[cf_cash_unit]?>
    </td>
    <td class="body left">
        <?=$list[$i][cl_content]?>
        <? if ($receipt) {?>
        <a href="#;" onclick="<?=$receipt?>" style="font-size:11px; color:#999; margin:0 0 0 10px;">[영수증]</a>
        <? } ?>
    </td>
</tr>
<? } ?>
<? if ($i==0) echo "<tr><td colspan=$colspan class=none>자료가 없습니다.</td></tr>"; ?>
</table>


<div class="paging"><?=$write_pages?></div>


<?
include_once("_tail.php");
?>
